import 'package:flutter/material.dart';

class Test_RenderObject extends StatefulWidget {
  const Test_RenderObject({super.key});

  @override
  State<Test_RenderObject> createState() => _Test_RenderObjectState();
}

class _Test_RenderObjectState extends State<Test_RenderObject> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: const Text('TestName')),
        body: Center(child: CustomWidget())
    );
  }
}


class CustomWidget extends LeafRenderObjectWidget {
  @override
  RenderObject createRenderObject(BuildContext context) {
    // 创建 RenderObject
    return RenderCustomObject();
  }

  @override
  void updateRenderObject(BuildContext context,
      RenderCustomObject renderObject) {
    // 更新 RenderObject
    super.updateRenderObject(context, renderObject);
  }
}

class RenderCustomObject extends RenderBox {

  @override
  void performLayout() {
    // 实现布局逻辑
    size = constraints.smallest; // 或 constraints.constrain(Size(width, height))
    size = Size(100, 100); // 示例：固定尺寸
  }

  @override
  void paint(PaintingContext context, Offset offset) {
    final Canvas canvas = context.canvas;
    final Paint paint = Paint()
      ..color = Colors.blue
      ..style = PaintingStyle.fill;
    canvas.drawRect(offset & size, paint);
  }
}